<?php
// +-------------------------------------------------------------------
// |
// +-------------------------------------------------------------------
// | Copyright (c) 2009-2016 All rights reserved.
// +-------------------------------------------------------------------
namespace Service\Api\V1;

use Think\Exception;

class BindMobile
{
    public $login = true; //是否需要登录才能访问该接口
    public $title = "绑定手机号";
    public $group = '个人中心';
    public $desc = "";

    public $input = [
        'mobile' => 'required;mobile;label=收件人手机号',
    ];

    public $output = [

    ];

    public function run($param, $uid, $login_info)
    {
        $ucenter = M('ucenter_member')->where(['mobile' =>$param['mobile']])->find();
        if(isset($ucenter['id'])) throw new Exception('该手机已绑定');


            $flag = M('ucenter_member')->where(['id' =>$uid])->save(['mobile' => $param['mobile']]);
            $flag1 = M('user')->where(['uid' =>$uid])->save(['mobile' => $param['mobile']]);
            if(!$flag || !$flag1){
                throw new \Exception('绑定失败');
            }

        return true;
    }
}